package com.flycms.web.feedback;

import com.flycms.core.entity.PageVo;
import com.flycms.core.entity.RestDataVo;
import com.flycms.module.feedback.model.Feedback;
import com.flycms.module.feedback.service.FeedbackService;
import com.flycms.module.feedback.param.FeedbackParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    /**
     * 意见反馈保存接口
     *
     * @param feedback 意见信息
     * @return 保存结果
     */
    @PostMapping("/feedback/save")
    public RestDataVo save(@RequestBody Feedback feedback) {
        try {
            feedbackService.save(feedback);
        } catch (Exception e) {
            e.printStackTrace();
            return RestDataVo.ERROR("提交意见失败");
        }
        return RestDataVo.OK("提交成功");
    }

    /**
     * 分页查询反馈意见
     *
     * @param param 查询参数
     * @return 返回结果
     */
    @GetMapping("/system/feedback/page")
    public RestDataVo getPage(FeedbackParam param) {
        PageVo<Feedback> feedbackPageVo = feedbackService.getPage(param);
        return RestDataVo.PAGE(feedbackPageVo.getList(), param.getPageIndex(), param.getPageSize(), feedbackPageVo.getCount());
    }

    /**
     * 删除反馈意见
     *
     * @return 返回结果
     */
    @DeleteMapping("/system/feedback/del/{id}")
    public RestDataVo del(@PathVariable("id") Long id) {
        try {
            feedbackService.delById(id);
        } catch (Exception e) {
            return RestDataVo.ERROR("删除失败");
        }
        return RestDataVo.OK("删除成功");
    }

}
